@extends('dashboard.base')

@section('content')

<div class="card-header"><a href="{{route('admin.goods.create')}}" class="btn btn-square  btn-info active">添加商品</a></div>

<form action="" method="get">
  <div class="form-group row p-2">
    <div class="col-sm">
      <input type="text" name="name" class="form-control" placeholder="商品名称" value="{{request()->name??''}}">
    </div>

    <div class="col-sm">
      @include('dashboard.includes.category_select', ['name' => 'category_id', 'default' => request()->category_id??''])
    </div>
    
    <div class="col-sm">
      @include('dashboard.components.brand_select', ['name' => 'brand_id'])
    </div>
    <div class="col-sm">
      <select class="form-control">
        <option value="">状态</option>
      </select>
    </div>
    <div class="col-sm">
      <button class="btn btn-info">搜索</button>
    </div>
  </div>
</form>

<table class="table table-responsive-sm">
  <thead>
    <tr>
      <th>商品图片</th>
      <th>商品名称</th>
      <th>状态</th>
      <th>分类</th>

      <th>价格</th>
      <th>库存</th>

      <th>销量</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    @each('dashboard.includes.goodslist', $datas, 'v')
  </tbody>
</table>
<p>{{ $datas->appends(request()->query())->links() }}</p>

<script type="text/javascript">
  $("a[data-type='status']").on('click', function() {
    const goods_id = $(this).data('goods_id')
    $.ajax({
      url:"status/"+goods_id,
      type:'put',
      success: res => {
        console.log(res)
        if(res.status == 1) {
          $(this).removeClass('badge-danger').addClass('badge-success').text('已上架');
        }
        else {
          $(this).removeClass('badge-success').addClass('badge-danger').text('已下架');
        }
      }
    })
  })
</script>
@endsection